package com.atguigu.gmall.user.service.impl;

import com.atguigu.gmall.common.utils.MD5;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.user.mapper.UserAddressMapper;
import com.atguigu.gmall.user.mapper.UserMapper;
import com.atguigu.gmall.user.service.UserService;
import com.atguigu.gmall.model.user.UserInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;


    @Autowired
    private UserAddressMapper useraddressMapper;
    @Override
    public UserInfo loginCheck(UserInfo userInfo) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("login_name",userInfo.getLoginName());
        wrapper.eq("passwd", MD5.encrypt(userInfo.getPasswd()));
        userInfo = userMapper.selectOne(wrapper);
        return userInfo;
    }

    //获取用户地址集合
    public List<UserAddress> getUserAddressList(String userId) {
        QueryWrapper<UserAddress> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        return useraddressMapper.selectList(wrapper);
    }
}
